/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package transaction.committee_management;

import common.exception.ExceptionHandler;
import common.util.HibernateUtil;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import transaction.add_committee.YearCommitteeStatus;

/**
 *
 * @author User
 */
public class SERCommitteeManager {

    static List getCommitteeMembers(String committee, String year) {
         Session session = HibernateUtil.getSession();
        Transaction transaction = session.beginTransaction();
        List list = new ArrayList();
        try {
            String hql = "from transaction.committee_management.object.YearCommittee where committee='" + committee + "' and year='" + year + "' and status in ('"+YearCommitteeStatus.ACTIVE+"', '"+YearCommitteeStatus.SUSPEND+"')";
            Query query = session.createQuery(hql);
            list = query.list();
            transaction.commit();
            return list;
        } catch (HibernateException e) {
            ExceptionHandler.show(e, "Retriving Committee Members Error..!", SERCommitteeManager.class);
            return null;
        } finally {
            HibernateUtil.closeSession();
            System.out.println("Closed Session in CommitteeMembers");
        }
    }

    static List getMembers() {
         Session session = HibernateUtil.getSession();
        Transaction transaction = session.beginTransaction();
        List list = new ArrayList();
        try {
            String hql = "from transaction.committee_management.object.Member";
            Query query = session.createQuery(hql);
            list = query.list();
            transaction.commit();
            
            return list;
        } catch (HibernateException e) {
            ExceptionHandler.show(e, "Retriving Members Error..!", SERCommitteeManager.class);
            return null;
        } finally {
            HibernateUtil.closeSession();
            System.out.println("Closed Session in Members");
        }
    }
    
    static List getCommittees(){
         Session session = HibernateUtil.getSession();
        Transaction transaction = session.beginTransaction();
        try {
            String hql = "from transaction.committee_management.object.Committee";
            Query query = session.createQuery(hql);
            List list = query.list();
            transaction.commit();
            return list;
        } catch (HibernateException e) {
            ExceptionHandler.show(e, "Retriving Committee Error..!", SERCommitteeManager.class);
            return null;
        } finally {
            HibernateUtil.closeSession();
            System.out.println("Closed Session in Committee");
        }
    }
    
    static List getYears(){
        Session session = HibernateUtil.getSession();
        Transaction transaction = session.beginTransaction();
        try {
            String hql = "from transaction.committee_management.object.Year";
            Query query = session.createQuery(hql);
            List list = query.list();
            transaction.commit();
            return list;
        } catch (HibernateException e) {
            ExceptionHandler.show(e, "Retriving Years Error..!", SERCommitteeManager.class);
            return null;
        } finally {
            HibernateUtil.closeSession();
            System.out.println("Closed Session in Year");
        }
    }
}
